<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
	      content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<link rel="stylesheet" type="text/css" href="./lib/formSelect/formSelects-v4.css"/>
	<script type="text/javascript" src="./js/abkj/match/api/itemdefine.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/matchtype.js"></script>
	<script type="text/javascript" src="./js/abkj/ext/matchExt.js"></script>
	<!-- 引入在线资源 -->
	<script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-6.4.0.min.js"></script>
	<script type="text/javascript" src="./js/abkj/oss/app.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/topic.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/grade.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/scheduleItemList.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/scheduletype.js"></script>

	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	<script src="./js/html5.min.js"></script>
	<script src="./js/respond.min.js"></script>
	<![endif]--></head>

<body>
<div class="layui-fluid" id="app">
	<div class="layui-row">
		<!--初始化复制， 需要在form上写 lay-fiter-->
		<form class="layui-form" lay-filter="matchForm">


			<div class="layui-form-item">
				<label style="margin-left: 30px;">
					<span class="x-red">*</span>赛程时间(勾选需要的赛程)</label>
				<div style="display: block">

						<section style="margin: 15px 105px;">
							比赛形式(勾选需要的赛程)
						</section>

					<section id="schedule2">
						<section id="schedule_sec" style="margin: 15px 105px;margin-top: 25px;">
							<input id="schedule_checkbox" style="margin-top: 0" type="checkbox" name="schedule_checkbox" title="复赛" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="schedule2_start"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="schedule2_end"></div>
						</section>
						<section style="margin: 15px 105px;">
							比赛形式(勾选需要的赛程)
						</section>
						<section id="scheduleItemList1" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="在线答题" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start21"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end21"></div>
						</section>

						<section id="scheduleItemList2" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="提交作品" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start22"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end22"></div>
						</section>
						<section id="scheduleItemList4" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="编程作品" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start24"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end24"></div>
						</section>
						<section id="scheduleItemList3" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="现场比赛" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start23"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end23"></div>
						</section>
					</section>

					<!-- </section> -->

				</div>
			</div>



			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label" style="width: 105px;"><span class="x-red">*</span>复赛赛参赛者须知</label>
				<div class="layui-input-inline">
          <textarea class="layui-textarea" id="LAY_demo2" style="display: none">

					</textarea>
				</div>
			</div>


			<div class="layui-form-item">
				<label class="layui-form-label"></label>
				<button class="layui-btn" lay-filter="add" id="add" lay-submit="">确认提交</button>
			</div>
		</form>
	</div>
</div>
<script src="./lib/formSelect/formSelects-v4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/vue.js"></script>
<script src="./js/jquery.min.js"></script>
<script>
var form
Date.prototype.Format = function(fmt)
	{ //author: meizz
		var o = {
			"M+" : this.getMonth()+1,                 //月份
			"d+" : this.getDate(),                    //日
			"h+" : this.getHours(),                   //小时
			"m+" : this.getMinutes(),                 //分
			"s+" : this.getSeconds(),                 //秒
			"q+" : Math.floor((this.getMonth()+3)/3), //季度
			"S"  : this.getMilliseconds()             //毫秒
		};
		if(/(y+)/.test(fmt))
			fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
		for(var k in o)
			if(new RegExp("("+ k +")").test(fmt))
		fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
		return fmt;
	}
var varOssImgUrl = ''
// oss 图片上传事件

function initSchduleItem(varRoot, varScheduleID, varItemId) {
	var varSchedule = varRoot.find('#scheduleItemList' + varItemId)
	var varIsSel = varSchedule.find('#itemsel').is(':checked')
	// alert(varIsSel)
	if (!varIsSel)
		return null
	var varItemObj = {
		itemId: varItemId,
		id:'',
		itemName: varSchedule.find('#itemsel').attr('title'),
		startTime:varSchedule.find('#start' + varScheduleID + varItemId).val() ,
		endTime:varSchedule.find('#end' + varScheduleID + varItemId).val()
	}
	return varItemObj
}
function toTime(strTime) {
 if (!strTime) {
    return '';
 }
 var myDate = new Date(strTime + '+0800');
 var d=new Date(strTime + '+0800');
 var d1=Date.UTC(d.getUTCFullYear(),d.getUTCMonth() ,d.getUTCDate(),d.getUTCHours()+8,d.getUTCMinutes(),d.getUTCSeconds())
 myDate=new Date(d1);
 if (myDate == 'Invalid Date') {
  strTime = strTime.replace(/T/g, ' ');
  strTime = strTime.replace(/-/g, '/');
  strTime = strTime.replace(/\.\d+/, ' ');//去掉毫秒
  myDate = new Date(strTime + '+0800');
 }
//  alert(myDate)
 return myDate; //输出的也是带T时间格式，但在安卓和ios上时间保持一致
}
function initSchedule(varID) {
	var varSchedule = $('#schedule' + varID).find('#schedule_sec')

	var varIsSel = varSchedule.find('#schedule_checkbox').is(':checked')
	// alert(varIsSel)
  if (varIsSel==false){
		return null
	}




	// var layedit = layui.layedit
	// var index = layedit.build("LAY_demo"+varID);

	var varSObj = {
		scheduleType: varID,
		scheduleName: varSchedule.find('#schedule_checkbox').attr('title'),
		startTime:varSchedule.find('#schedule' + varID + '_start').val(),
		endTime:varSchedule.find('#schedule' + varID + '_end').val(),
		notice: $('#LAY_demo' + varID).val(),
		//notice:layedit.getText(index),
		topicId: $('#selectTopic').val(),
		topicName: $('#selectTopic').find('option:selected').text()
	}

	// 对应 MatchScheduleReqParamVO
	var varScheduleReq = {
		schedule: varSObj,
		scheduleItemList: []
	}
	for (var i = 1; i < 5; ++i) {
		var varItem = initSchduleItem($('#schedule' + varID), varID, i)
		if (varItem != null) {
			varScheduleReq.scheduleItemList.push(varItem)
		}
	}
	// alert(JSON.stringify(varScheduleReq))
	// console.log(varScheduleReq)
	// alert(varScheduleReq)
	return varScheduleReq
}

function initMatchObj() {
	var matchObj = {
		theme: $('#theme').val(),
		type: $('#selectMatchType').val(),
		typeName: $('#selectMatchType').find('option:selected').text(),
		mainImg: varOssImgUrl,
		introduction: $('#introduction').val(),
		multiplayer: $('#multiplayer').val()
	}
	return matchObj
}
</script>
<script>
var tool = fun_tool()
var myshuju,myshuju1,myshuju2
var app = new Vue({
	el: '#app',
	data: {
		id: tool.getUrlParam('id'),
		scheduleItemList: 'scheduleItemList',
		scheduletypeList: [],
		gradeList: [],
		zoneList: [],
		topicList: [],
		matchTypeList: [],
		ItemDefine: [],
		relist:[],

	},
	mounted: function () {


	},
	methods: {
		loadGradeList: function () {
			GradequeryList({}, function (data) {
				app.gradeList = data

				for (var i = 0; i < data.length; ++i) {
					var varApStr = '<input type="checkbox" name="mygrade" title="' + data[i].gradeName + '" value="' + data[i].id +
						'" id="grade' + data[i].id + '" lay-skin="primary">'
				  // alert(document.getElementById("graderoot").innerHTML)
					$('#graderoot').append(varApStr)
				}
				layui.use('form', function () {
					 form = layui.form //
					form.render()
				})
			}, function (status, message) {
				alert(message)
			})
		},
		loadZoneList: function () {
			ZonequeryList({}, function (data) {
				app.zoneList = data
				var formSelects = layui.formSelects
				var varArr = []
				for (var i = 0; i < data.length; ++i) {
					var arrItem = {
						name: data[i].zoneName,
						value: data[i].id
					}
					varArr.push(arrItem)
				}
				formSelects.data('select1', 'local', {
					arr: varArr
				})
			}, function (status, message) {
				alert(message)
			})
		},
		loadTopicList: function () {
			TopicqueryList({}, function (data) {
				app.topicList = data
				var varApStr = '<option value="">请选择</option>'
				$('#selectTopic').append(varApStr)
				for (var i = 0; i < data.length; ++i) {
					varApStr = '<option value="' + data[i].id + '">' + data[i].name + '</option>'
					$('#selectTopic').append(varApStr)
				}
				layui.use('form', function () {
					 form = layui.form //
					form.render()
				})
			}, function (status, message) {

			})
		},
		loadMatchType: function () {
			MatchTypequeryList({}, function (data) {
				app.matchTypeList = data
				var varApStr = '<option value="">请选择</option>'
				$('#selectMatchType').append(varApStr)
				for (var i = 0; i < data.length; ++i) {
					varApStr = '<option value="' + data[i].id + '">' + data[i].name + '</option>'
					$('#selectMatchType').append(varApStr)
				}
				layui.use('form', function () {
					 form = layui.form //
					form.render()
				})
			})
		},
		loadItemDefine: function () {
			ItemDefinequeryList({}, function (data) {
				app.ItemDefine = data
				console.log(data)
			})
		},
		loadScheduleType: function () {
			ScheduleTypequeryList({}, function (data) {
				app.scheduletypeList = data
			})
		},
		getData: function () {
			var vm=this

			var querydata={
				matchId:localStorage.bisaiid,
				scheduleType:2,
				zoneId:vm.id
			}
			getCorrectTime(querydata, function (data) {
				    //  alert(JSON.stringify(data))
			     if (JSON.stringify(data)!='[]'){
						 var chedulesList
						 if (data[0]){
							 chedulesList=data[0]
						 }
						 else {
							 chedulesList=data
						 }

						  var schedule_checkbox=document.getElementsByName("schedule_checkbox")
							// alert(chedulesList)

								   // alert(chedulesList.scheduleName)
									 if (chedulesList.scheduleName==''||chedulesList.scheduleName=='复赛'){
										 schedule_checkbox[0].checked=true
										 document.getElementById("schedule2_start").value=new Date(chedulesList.startTime).Format("yyyy-MM-dd hh:mm:ss")
										 document.getElementById("schedule2_end").value=new Date(chedulesList.endTime).Format("yyyy-MM-dd hh:mm:ss")
										 myshuju=chedulesList.notice


											layui.use('layedit', function () {
											 layedit = layui.layedit
												, $ = layui.jquery

											 //构建一个默认的编辑器

											 //构建一个默认的编辑器

											 index2 = layedit.build('LAY_demo2')


												bianjiqi1=index2

											 layedit.setContent(bianjiqi1, myshuju, false);
											 //编辑器外部操作

											 // $('.site-demo-layedit').on('click', function () {
											 // 	var type = $(this).data('type');
											 // 	active[type] ? active[type].call(this) : '';
											 // });
											})


										 layui.form.render('checkbox');
										 chedulesList.scheduleItemList=JSON.parse(chedulesList.scheduleItemList)
										 // alert(chedulesList.scheduleItemList.length)
										 for (j=0;j<chedulesList.scheduleItemList.length;j++){
												//
												// alert(chedulesList.scheduleItemList[j].itemName)
												if (chedulesList.scheduleItemList[j].itemName=='在线答题'){
													document.getElementsByName("itemsel")[0].checked=true
													document.getElementById("start21").value=new Date(chedulesList.scheduleItemList[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
													document.getElementById("end21").value=new Date(chedulesList.scheduleItemList[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



												}
												else if (chedulesList.scheduleItemList[j].itemName=='提交作品'){
													document.getElementsByName("itemsel")[1].checked=true
													document.getElementById("start22").value=new Date(chedulesList.scheduleItemList[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												 document.getElementById("end22").value=new Date(chedulesList.scheduleItemList[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



												}
												else if (chedulesList.scheduleItemList[j].itemName=='编程作品'){
													document.getElementsByName("itemsel")[2].checked=true
													document.getElementById("start24").value=new Date(chedulesList.scheduleItemList[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
													document.getElementById("end24").value=new Date(chedulesList.scheduleItemList[j].endTime).Format("yyyy-MM-dd hh:mm:ss")




											 }
												else if (chedulesList.scheduleItemList[j].itemName=='现场比赛'){
													document.getElementsByName("itemsel")[3].checked=true
													document.getElementById("start23").value=new Date(chedulesList.scheduleItemList[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												 document.getElementById("end23").value=new Date(chedulesList.scheduleItemList[j].endTime).Format("yyyy-MM-dd hh:mm:ss")




											 }
											 layui.form.render('checkbox');

										 }





							}
					 }
			})


		}
	}
})
window.onload = function () {
	app.getData()
}

</script>
<script>
var bianjiqi
var bianjiqi1
var bianjiqi2
var layedit

layui.use('layedit', function () {
	layedit = layui.layedit
	 , $ = layui.jquery
	 layedit = layui.layedit
		, $ = layui.jquery
		layedit.set({
	uploadImage:{
	url:"http://47.114.219.249:88/thirdplat-provider/oss/putfile",//接口url
	//url:"http://localhost:8092/login/putfile",
	type:'post'//默认post
}
});

 //构建一个默认的编辑器

	//构建一个默认的编辑器
	 index = layedit.build('LAY_demo1')
	index2 = layedit.build('LAY_demo2')
  index3 = layedit.build('LAY_demo3')
	bianjiqi=index
  bianjiqi1=index2
	bianjiqi2=index3
	//编辑器外部操作

	// $('.site-demo-layedit').on('click', function () {
	// 	var type = $(this).data('type');
	// 	active[type] ? active[type].call(this) : '';
	// });
})
layui.use('upload', function () {
	var $ = layui.jquery
		, upload = layui.upload

	//普通图片上传
	var uploadInst = upload.render({
		elem: '#test1',
		auto: false,
		// multiple: true,
		acceptMime: 'image/png',
		choose: function (obj) {
			//预读本地文件示例，不支持ie8
			obj.preview(function (index, file) {
				// console.log($('#test1'))
				// initSchedule(1);
				// initSchedule(2);
				// initSchedule(3);
				// var formSelects = layui.formSelects;
				// console.log(formSelects.value('select1', 'val'))
				// var selGrade=[]
				// for(var i=0;i<app.gradeList.length;++i){
				// 	var isCheck = $("#grade"+app.gradeList[i].id).is(":checked")
				// 	if(isCheck){
				// 		selGrade.push(app.gradeList[i].id)
				// 	}
				// }
				// console.log(selGrade)
				applyTokenDo(file, function (ret) {
					varOssImgUrl = 'https://dzxh.oss-cn-hangzhou.aliyuncs.com/' + ret.name
					$('#demo1').show().css('background-image', 'url(' + varOssImgUrl + ')') //图片链接（base64）
				}, function (ret) {

				})

			})
		},
		error: function () {
			//演示失败状态，并实现重传
			var demoText = $('#demoText')
			demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>')
			demoText.find('.demo-reload').on('click', function () {
				uploadInst.upload()
			})
		}
	})
})

layui.use('laydate',
	function () {
		var laydate = layui.laydate
		for (var i = 1; i < 4; ++i) {
			//执行一个laydate实例
			laydate.render({
				elem: '#schedule' + i + '_start', //指定元素
				type: 'datetime',
        trigger: 'click'
			})
			laydate.render({
				elem: '#schedule' + i + '_end' ,
				type: 'datetime',
        trigger: 'click'
			})
			for (var t = 1; t < 5; ++t) {
				laydate.render({
					elem: '#start' + i + t,
					type: 'datetime',
	        trigger: 'click'
				})
				laydate.render({
					elem: '#end' + i + t ,
					type: 'datetime',
	        trigger: 'click'
				})
			}
		}
		//执行一个laydate实例
		laydate.render({
			elem: '#start',
			type: 'datetime',
			trigger: 'click'
		})

		laydate.render({
			elem: '#start1',
			type: 'datetime',
			trigger: 'click'
		})
		laydate.render({
			elem: '#start2' ,
			type: 'datetime',
			trigger: 'click'
		})
		//执行一个laydate实例
		laydate.render({
			elem: '#end' ,
			type: 'datetime',
			trigger: 'click'
		})
		laydate.render({
			elem: '#end1' ,
			type: 'datetime',
			trigger: 'click'
		})
		laydate.render({
			elem: '#end2' ,
			type: 'datetime',
			trigger: 'click'
		})

	})
layui.use(['form', 'layer'], function () {
		$ = layui.jquery
		 form = layui.form,
			layer = layui.layer

		//自定义验证规则
		// form.verify({
		// 	username: function (value) {
		// 		if (value.length < 5) {
		// 			return '主题至少得5个字符啊';
		// 		}
		// 	},
		// 	pass: [/(.+){6,12}$/, '密码必须6到12位'],
		// 	repass: function (value) {
		// 		if ($('#L_pass').val() != $('#L_repass').val()) {
		// 			return '两次密码不一致';
		// 		}
		// 	}
		// });

		//监听提交
		form.on('submit(add)',
			function (data) {

				// alert(JSON.stringify(data))
				//发异步，把数据提交给php
				var formSelects = layui.formSelects
				var reqParam = {
					matchId:localStorage.bisaiid,
					scheduleType:2,
					zoneId:app.id,

				  startTime:toTime( document.getElementById('schedule2_start').value),
				   endTime:toTime(document.getElementById('schedule2_end').value),
				   notice:layedit.getContent(bianjiqi1),
					 scheduleItemList:''
				}

				for (var i = 1; i < 4; ++i) {
					var varItem = initSchedule(i)
					if (varItem != null) {
						// alert(JSON.stringify(varItem.scheduleItemList))
						reqParam.scheduleItemList=JSON.stringify(varItem.scheduleItemList)
					}
				}




        //
				    console.log(JSON.stringify(reqParam))
					addCorrectTime(reqParam, function (data) {
					  // alert(JSON.stringify(data))
						alert("修改成功！")
						var index = parent.layer.getFrameIndex(window.name)
						//关闭当前frame
						parent.layer.close(index)

						// 可以对父窗口进行刷新
						xadmin.father_reload()
					})

			})

	})</script>
<script>var _hmt = _hmt || [];
(function () {
	var hm = document.createElement('script')
	hm.src = 'https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190'
	var s = document.getElementsByTagName('script')[0]
	s.parentNode.insertBefore(hm, s)
})()</script>
</body>

</html>
